<?php

class TableRow {

    private $id;
    private $style;
    private $cells;

    public function __construct() {
        $this->style = '';
        $this->id = '';
    }

    public function addCell($id, $data, $style = '', $colspan = '', $rowspan = '') {

        $this->cells[] = array($id, $data, $style, $colspan, $rowspan);
    }

    public function getId() {
        return $this->id;
    }

    public function setId($id) {
        $this->id = $id;
    }

    public function getStyle() {
        return $this->style;
    }

    public function setStyle($style) {
        $this->style = $style;
    }

    public function generate() {
        $html = array();
        if (count($this->cells)) {
            $html[] = '<tr id="' . $this->id . '">';
//            $amplia = FALSE;
//            $ind = 0;
//            $mostrar = TRUE;
//
//            $ultimo = count($this->cells);
            foreach ($this->cells as $cell) {
                $colspan = $cell[3];


                //si el texto de pasa del limite
//                if ($ind < $ultimo - 1)
//                    $siguiente = $this->cells[$ind + 1];
//                if (strlen($cell[1]) > 50 && $siguiente[1] == '') {
//                    //marco para ampliar la celda
//                    $colspan = 2;
//                    $amplia = TRUE;
//                }
//
//                if ($mostrar) {
                    $html[] = '<td colspan="' . $colspan . '" rowspan="' . $cell[4] . '" id="' . $cell[0] . '" style="' . $this->style . ';' . $cell[2] . '">';
                    $html[] = $cell[1];
                    $html[] = '</td>';
//                    if ($amplia)
//                        $mostrar = FALSE;
//                } else {
//                    $mostrar = TRUE;
//                    $amplia = FALSE;
//                }
//
//                $ind++;
            }
            $html[] = '</tr>';
        }
        $out = '';
        foreach ($html as $code) {
            $out = $out . $code;
        }
        return $out;
    }

}

?>
